home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / db_printview.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  11.9 KB  |  358 lines

  1. <?php
  2. /* $Id: db_printview.php,v 1.29 2003/07/19 11:10:20 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Gets the variables sent or posted to this script, then displays headers
  8.  */
  9. require('./libraries/grab_globals.lib.php');
  10. require('./header.inc.php');
  11.  
  12. // Check parameters
  13.  
  14. if (!defined('PMA_COMMON_LIB_INCLUDED')) {
  15.     include('./libraries/common.lib.php');
  16. }
  17.  
  18. PMA_checkParameters(array('db'));
  19.  
  20. /**
  21.  * Defines the url to return to in case of error in a sql statement
  22.  */
  23. $err_url = 'db_details.php?' . PMA_generate_common_url($db);
  24.  
  25. /**
  26.  * Settings for relations stuff
  27.  */
  28. require('./libraries/relation.lib.php');
  29. $cfgRelation = PMA_getRelationsParam();
  30.  
  31. /**
  32.  * Gets the list of the table in the current db and informations about these
  33.  * tables if possible
  34.  */
  35. // staybyte: speedup view on locked tables - 11 June 2001
  36. if (PMA_MYSQL_INT_VERSION >= 32303) {
  37.     // Special speedup for newer MySQL Versions (in 4.0 format changed)
  38.     if ($cfg['SkipLockedTables'] == TRUE && PMA_MYSQL_INT_VERSION >= 32330) {
  39.         $local_query  = 'SHOW OPEN TABLES FROM ' . PMA_backquote($db);
  40.         $result        = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  41.         // Blending out tables in use
  42.         if ($result != FALSE && mysql_num_rows($result) > 0) {
  43.             while ($tmp = PMA_mysql_fetch_array($result)) {
  44.                 // if in use memorize tablename
  45.                 if (eregi('in_use=[1-9]+', $tmp[0])) {
  46.                     $sot_cache[$tmp[0]] = TRUE;
  47.                 }
  48.             }
  49.             mysql_free_result($result);
  50.  
  51.             if (isset($sot_cache)) {
  52.                 $local_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
  53.                 $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  54.                 if ($result != FALSE && mysql_num_rows($result) > 0) {
  55.                     while ($tmp = PMA_mysql_fetch_array($result)) {
  56.                         if (!isset($sot_cache[$tmp[0]])) {
  57.                             $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\'';
  58.                             $sts_result  = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  59.                             $sts_tmp     = PMA_mysql_fetch_array($sts_result);
  60.                             $tables[]    = $sts_tmp;
  61.                         } else { // table in use
  62.                             $tables[]    = array('Name' => $tmp[0]);
  63.                         }
  64.                     }
  65.                     mysql_free_result($result);
  66.                     $sot_ready = TRUE;
  67.                 }
  68.             }
  69.         }
  70.     }
  71.     if (!isset($sot_ready)) {
  72.         $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db);
  73.         $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  74.         if ($result != FALSE && mysql_num_rows($result) > 0) {
  75.             while ($sts_tmp = PMA_mysql_fetch_array($result)) {
  76.                 $tables[] = $sts_tmp;
  77.             }
  78.             mysql_free_result($result);
  79.         }
  80.     }
  81.     $num_tables = (isset($tables) ? count($tables) : 0);
  82. } // end if (PMA_MYSQL_INT_VERSION >= 32303)
  83. else {
  84.     $result     = PMA_mysql_list_tables($db);
  85.     $num_tables = ($result) ? @mysql_numrows($result) : 0;
  86.     for ($i = 0; $i < $num_tables; $i++) {
  87.         $tables[] = PMA_mysql_tablename($result, $i);
  88.     }
  89.     mysql_free_result($result);
  90. }
  91.  
  92. if ($cfgRelation['commwork']) {
  93.     $comment = PMA_getComments($db);
  94.  
  95.     /**
  96.      * Displays DB comment
  97.      */
  98.     if (is_array($comment)) {
  99.         ?>
  100.     <!-- DB comment -->
  101.     <p><i>
  102.         <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
  103.     </i></p>
  104.         <?php
  105.     } // end if
  106. }
  107.  
  108. /**
  109.  * If there is at least one table, displays the printer friendly view, else
  110.  * an error message
  111.  */
  112. // 1. No table
  113. if ($num_tables == 0) {
  114.     echo $strNoTablesFound;
  115. }
  116. // 2. Shows table informations on mysql >= 3.23.03 - staybyte - 11 June 2001
  117. else if (PMA_MYSQL_INT_VERSION >= 32303) {
  118.     ?>
  119.  
  120. <!-- The tables list -->
  121. <table border="<?php echo $cfg['Border']; ?>">
  122. <tr>
  123.     <th> <?php echo $strTable; ?> </th>
  124.     <th><?php echo $strRecords; ?></th>
  125.     <th><?php echo $strType; ?></th>
  126.     <?php
  127.     if ($cfg['ShowStats']) {
  128.         echo '<th>' . $strSize . '</th>';
  129.     }
  130.     echo "\n";
  131.     ?>
  132.     <th><?php echo $strComments; ?></th>
  133. </tr>
  134.     <?php
  135.     $i = $sum_entries = $sum_size = 0;
  136.     while (list($keyname, $sts_data) = each($tables)) {
  137.         $table     = $sts_data['Name'];
  138.         $bgcolor   = ($i++ % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
  139.         echo "\n";
  140.         ?>
  141. <tr>
  142.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  143.          <b><?php echo htmlspecialchars($table); ?> </b> 
  144.     </td>
  145.         <?php
  146.         echo "\n";
  147.         $mergetable         = FALSE;
  148.         $nonisam            = FALSE;
  149.         if (isset($sts_data['Type'])) {
  150.             if ($sts_data['Type'] == 'MRG_MyISAM') {
  151.                 $mergetable = TRUE;
  152.             } else if (!eregi('ISAM|HEAP', $sts_data['Type'])) {
  153.                 $nonisam    = TRUE;
  154.             }
  155.         }
  156.  
  157.         if (isset($sts_data['Rows'])) {
  158.             if ($mergetable == FALSE) {
  159.                 if ($cfg['ShowStats'] && $nonisam == FALSE) {
  160.                     $tblsize                        =  $sts_data['Data_length'] + $sts_data['Index_length'];
  161.                     $sum_size                       += $tblsize;
  162.                     if ($tblsize > 0) {
  163.                         list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 1);
  164.                     } else {
  165.                         list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 0);
  166.                     }
  167.                 } else if ($cfg['ShowStats']) {
  168.                     $formated_size                  = ' - ';
  169.                     $unit                           = '';
  170.                 }
  171.                 $sum_entries                        += $sts_data['Rows'];
  172.             }
  173.             // MyISAM MERGE Table
  174.             else if ($cfg['ShowStats'] && $mergetable == TRUE) {
  175.                 $formated_size = ' - ';
  176.                 $unit          = '';
  177.             }
  178.             else if ($cfg['ShowStats']) {
  179.                 $formated_size = 'unknown';
  180.                 $unit          = '';
  181.             }
  182.             ?>
  183.     <td align="right" bgcolor="<?php echo $bgcolor; ?>">
  184.             <?php
  185.             echo "\n" . '        ';
  186.             if ($mergetable == TRUE) {
  187.                 echo '<i>' . number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . '</i>' . "\n";
  188.             } else {
  189.                 echo number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n";
  190.             }
  191.             ?>
  192.     </td>
  193.     <td nowrap="nowrap" bgcolor="<?php echo $bgcolor; ?>">
  194.          <?php echo (isset($sts_data['Type']) ? $sts_data['Type'] : ' '); ?> 
  195.     </td>
  196.             <?php
  197.             if ($cfg['ShowStats']) {
  198.                 echo "\n";
  199.                 ?>
  200.     <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  201.          <?php echo $formated_size . ' ' . $unit . "\n"; ?>
  202.     </td>
  203.                 <?php
  204.                 echo "\n";
  205.             } // end if
  206.         } else {
  207.             ?>
  208.     <td colspan="3" align="center" bgcolor="<?php echo $bgcolor; ?>">
  209.         <?php echo $strInUse . "\n"; ?>
  210.     </td>
  211.             <?php
  212.         }
  213.         echo "\n";
  214.         ?>
  215.     <td bgcolor="<?php echo $bgcolor; ?>">
  216.         <?php echo $sts_data['Comment']; ?>
  217.         <?php
  218.             if (!empty($sts_data['Comment'])) {
  219.                 $needs_break = '<br />';
  220.             } else {
  221.                 $needs_break = '';
  222.             }
  223.             
  224.             if ((isset($sts_data['Create_time']) && !empty($sts_data['Create_time']))
  225.                  || (isset($sts_data['Update_time']) && !empty($sts_data['Update_time']))
  226.                  || (isset($sts_data['Check_time']) && !empty($sts_data['Check_time']))) {
  227.                 echo $needs_break;
  228.                 ?>
  229.                 <table border="0" cellpadding="1" cellspacing="1" width="100%">
  230.                 <?php
  231.             
  232.                 if (isset($sts_data['Create_time']) && !empty($sts_data['Create_time'])) {
  233.                     ?>
  234.                     <tr>
  235.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo $strStatCreateTime . ': '; ?></td>
  236.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo PMA_localisedDate(strtotime($sts_data['Create_time'])); ?></td>
  237.                     </tr>
  238.                     <?php
  239.                 }
  240.     
  241.                 if (isset($sts_data['Update_time']) && !empty($sts_data['Update_time'])) {
  242.                     ?>
  243.                     <tr>
  244.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo $strStatUpdateTime . ': '; ?></td>
  245.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo PMA_localisedDate(strtotime($sts_data['Update_time'])); ?></td>
  246.                     </tr>
  247.                     <?php
  248.                 }
  249.     
  250.                 if (isset($sts_data['Check_time']) && !empty($sts_data['Check_time'])) {
  251.                     ?>
  252.                     <tr>
  253.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo $strStatCheckTime . ': '; ?></td>
  254.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo PMA_localisedDate(strtotime($sts_data['Check_time'])); ?></td>
  255.                     </tr>
  256.                     <?php
  257.                 }
  258.                 ?>
  259.                 </table>
  260.                 <?php
  261.             }
  262.         ?>
  263.     </td>
  264. </tr>
  265.         <?php
  266.     }
  267.     // Show Summary
  268.     if ($cfg['ShowStats']) {
  269.         list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
  270.     }
  271.     echo "\n";
  272.     ?>
  273. <tr>
  274.     <th align="center">
  275.          <b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b> 
  276.     </th>
  277.     <th align="right" nowrap="nowrap">
  278.         <b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
  279.     </th>
  280.     <th align="center">
  281.         <b>--</b>
  282.     </th>
  283.     <?php
  284.     if ($cfg['ShowStats']) {
  285.         echo "\n";
  286.         ?>
  287.     <th align="right" nowrap="nowrap">
  288.         <b><?php echo $sum_formated . ' ' . $unit; ?></b>
  289.     </th>
  290.         <?php
  291.     }
  292.     echo "\n";
  293.     ?>
  294.     <th> </th>
  295. </tr>
  296. </table>
  297.     <?php
  298. } // end case mysql >= 3.23.03
  299.  
  300. // 3. Shows tables list mysql < 3.23.03
  301. else {
  302.     $i = 0;
  303.     echo "\n";
  304.     ?>
  305.  
  306. <!-- The tables list -->
  307. <table border="<?php echo $cfg['Border']; ?>">
  308. <tr>
  309.     <th> <?php echo $strTable; ?> </th>
  310.     <th><?php echo $strRecords; ?></th>
  311. </tr>
  312.     <?php
  313.     while ($i < $num_tables) {
  314.         $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $bgcolor = $cfg['BgcolorTwo'];
  315.         echo "\n";
  316.         ?>
  317. <tr>
  318.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  319.         <b><?php echo htmlspecialchars($tables[$i]); ?> </b>
  320.     </td>
  321.     <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  322.          <?php PMA_countRecords($db, $tables[$i]); ?>
  323.     </td>
  324. </tr>
  325.         <?php
  326.         $i++;
  327.     } // end while
  328.     echo "\n";
  329.     ?>
  330. </table>
  331.     <?php
  332. } // end if
  333.  
  334.  
  335. /**
  336.  * Displays the footer
  337.  */
  338. echo "\n";
  339. ?>
  340. <script type="text/javascript" language="javascript1.2">
  341. <!--
  342. function printPage()
  343. {
  344.     document.all.print.style.visibility = 'hidden';
  345.     // Do print the page
  346.     if (typeof(window.print) != 'undefined') {
  347.         window.print();
  348.     }
  349.     document.all.print.style.visibility = '';
  350. }
  351. //-->
  352. </script>
  353. <?php
  354. echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
  355.  
  356. require('./footer.inc.php');
  357. ?>
  358.